Skip to content

Support compiling with ClangCL and Visual Studio#5259

Closed
buresu wants to merge 1 commit intolightgbm-org:masterfrom
buresu:fix-vs-clang
Closed

Support compiling with ClangCL and Visual Studio#5259
buresu wants to merge 1 commit intolightgbm-org:masterfrom
buresu:fix-vs-clang

Conversation

@buresu
Copy link
Copy Markdown

@buresu buresu commented Jun 1, 2022

build with the following commands.

cmake .. -G "Visual Studio 16 2019" -T ClangCL -A x64
cmake --build . --config Release

@jameslamb jameslamb changed the title fix build with visual studio clang Support compiling with ClangCL and Visual Studio Jun 4, 2022
Copy link
Copy Markdown
Member

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this proposal! I hadn't heard of clang-cl until today. Will need to do a bit of research on this, and maybe test with a new CI job.

Links I'm finding useful (for the benefit of other reviewers):

@buresu
Copy link
Copy Markdown
Author

buresu commented Jun 5, 2022

Thank you for reviewing.
This is a common clang build problem, but I can't reproduce on linux clang, so I exemplified on visual studio clang.

@StrikerRUS
Copy link
Copy Markdown
Collaborator

What I've learned from links in #5259 (review) so far (thanks a lot @jameslamb for them!):

@jameslamb
Copy link
Copy Markdown
Member

This is a common clang build problem, but I can't reproduce on linux clang

This project is tested with clang on Linux and macOS on every commit, so I'd be surprised to learn that an issue of the form "LightGBM cannot be compiled with any version of clang" exists.

https://github.com/microsoft/LightGBM/blob/27d9ad2e8e7ea2d00dbab7b17b0a34b5d9184fe0/.vsts-ci.yml#L88-LL91

https://github.com/microsoft/LightGBM/blob/27d9ad2e8e7ea2d00dbab7b17b0a34b5d9184fe0/.vsts-ci.yml#L225-LL228

https://github.com/microsoft/LightGBM/blob/27d9ad2e8e7ea2d00dbab7b17b0a34b5d9184fe0/.ci/test.sh#L3-L9

https://github.com/microsoft/LightGBM/blob/27d9ad2e8e7ea2d00dbab7b17b0a34b5d9184fe0/.github/workflows/python_package.yml#L60-LL66

That is probably why you haven't been able to reproduce this on Linux. I suspect the issue you've faced is specific to using ClangCL + MSVC on Winddows.

@buresu
Copy link
Copy Markdown
Author

buresu commented Jun 6, 2022

@jameslamb I beleave this problem is also occurd on linux (in some cases).
Clang openmp requires a link path to libomp, but on linux libomp is usually installed on the system (e.g. libomp-dev).
Because this path is already added to link path, linker can find libomp.
If we use libomp outside the system path, I think we need to a link path to libomp.
I think apple clang probably uses libomp installed by brew, which causes same problem.

@buresu
Copy link
Copy Markdown
Author

buresu commented Jun 6, 2022

After noticing the above, I built on the vc prompt and the build went through without this change.
Sorry for the confusion. I will close this PR.

@buresu buresu closed this Jun 6, 2022
@jameslamb
Copy link
Copy Markdown
Member

@buresu sorry, could you clarify? Are you saying that the following worked for you with with 0 modifications to LightGBM?

cmake .. -G "Visual Studio 16 2019" -T ClangCL -A x64
cmake --build . --config Release

Or did you have to modify CMakeLists.txt or something in python-package/ to compile successfully?

@buresu
Copy link
Copy Markdown
Author

buresu commented Jun 8, 2022

@jameslamb Yes, the build successful with zero changes using vc prompt.
When using powershell the build succeeded with this PR change, but it was linking llvm openmp installed by scoop. (This is my mistake).
When built using powershell with no changes, vc's openmp was not found.
I think this is a lack of support from cmake.

@jameslamb
Copy link
Copy Markdown
Member

ahhh ok, thanks for the additional information @buresu !

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues
including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants